package org.jeecg.modules.demo3.peijian.utill;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.checkerframework.checker.units.qual.A;
import org.jeecg.modules.demo3.peijian.entity.*;
import org.jeecg.modules.demo3.peijian.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * @author wjn
 * @version V1.0
 * @date 2021/4/27 16:22
 * @Copyright © 2021/4/27 深圳卓翼航空无人机有限公司
 */
@Component
public class AddObject {
    @Autowired
    private AxhkXxwyLinearRegulatoMapper axhkXxwyLinearRegulatoMapper;//线性稳压
    @Autowired
    private AxhkXpShipMapper axhkXpShipMapper;//芯片
    @Autowired
    private AxhkQtElseMapper axhkQtElseMapper;//其他
    @Autowired
    private AxhkPjJcjMapper axhkPjJcjMapper;//接插件
    @Autowired
    private AxhkPjClqMapper axhkPjClqMapper;//处理器
    @Autowired
    private AxhkEsDiodeMapper axhkEsDiodeMapper;//二三级管
    @Autowired
    private AxhkDzResistanceMapper axhkDzResistanceMapper;//电阻
    @Autowired
    private AxhkDrCapacitanceMapper axhkDrCapacitanceMapper;//电容
    @Autowired
    private AxhkDgInductanceMapper axhkDgInductanceMapper;//电感
    @Autowired
    private AxhkCxMosMapper axhkCxMosMapper;//场效应
    @Autowired
    private AxhkAllResistanceMapper axhkAllResistanceMapper;//所有

    public static AddObject addObject;
    @PostConstruct
    public void init() {
        addObject = this;
        addObject.axhkDzResistanceMapper = this.axhkDzResistanceMapper;
        addObject.axhkXxwyLinearRegulatoMapper = this.axhkXxwyLinearRegulatoMapper;
        addObject.axhkXpShipMapper = this.axhkXpShipMapper;
        addObject.axhkQtElseMapper = this.axhkQtElseMapper;
        addObject.axhkPjJcjMapper = this.axhkPjJcjMapper;
        addObject.axhkPjClqMapper = this.axhkPjClqMapper;
        addObject.axhkEsDiodeMapper = this.axhkEsDiodeMapper;
        addObject.axhkDrCapacitanceMapper = this.axhkDrCapacitanceMapper;
        addObject.axhkDgInductanceMapper = this.axhkDgInductanceMapper;
        addObject.axhkCxMosMapper = this.axhkCxMosMapper;
        addObject.axhkAllResistanceMapper = this.axhkAllResistanceMapper;
    }

    //对数据进行添加
    //电阻（num=1）\电容（num=2）\电感（num=3）\二极管/晶体管（num=4）
    //场效应管（num=5）\电源芯片（num=6）\芯片（num=7）\处理器（num=8）
    //接插件（num=9）\其他（num=10）
    public int getAdd(Object obj,int num){
        int i = 0;
        ObjectMapper objectMapper = new ObjectMapper();
        switch (num){
            case 0:{
                //电阻
                AxhkDzResistance axhkDzResistance = objectMapper.convertValue(obj,AxhkDzResistance.class);
                i = addObject.axhkDzResistanceMapper.getInsertDzResistance(axhkDzResistance);
                break;
            }
            case 1:{
                //电容
                AxhkDrCapacitance axhkDzResistance = objectMapper.convertValue(obj,AxhkDrCapacitance.class);
                i = addObject.axhkDrCapacitanceMapper.getInsertDrCapacitance(axhkDzResistance);
                break;
            }
            case 5:{
                //电感
                AxhkDgInductance axhkDgInductance = objectMapper.convertValue(obj,AxhkDgInductance.class);
                i = addObject.axhkDgInductanceMapper.getInsertDgInductance(axhkDgInductance);
                break;
            }
            case 4:{
                //二极管\晶体管
                AxhkEsDiode axhkEsDiode = objectMapper.convertValue(obj,AxhkEsDiode.class);
                i = addObject.axhkEsDiodeMapper.getInsertAxhkEsDiode(axhkEsDiode);
                break;
            }
            case 6:{
                //场效应管
                AxhkCxMos axhkCxMos = objectMapper.convertValue(obj,AxhkCxMos.class);
                i = addObject.axhkCxMosMapper.getInsertAxhkCxMos(axhkCxMos);
                break;
            }
            case 3:{
                //电源芯片
                AxhkXxwyLinearRegulato axhkXxwyLinearRegulato = objectMapper.convertValue(obj,AxhkXxwyLinearRegulato.class);
                i = addObject.axhkXxwyLinearRegulatoMapper.getInsertLinearRegulato(axhkXxwyLinearRegulato);
                break;
            }
            case 2:{
                //芯片
                AxhkXpShip axhkXpShip = objectMapper.convertValue(obj,AxhkXpShip.class);
                i = addObject.axhkXpShipMapper.getInsertXpShip(axhkXpShip);
                break;
            }
            case 9:{
                //处理器
                AxhkPjClq axhkPjClq = objectMapper.convertValue(obj,AxhkPjClq.class);
                i = addObject.axhkPjClqMapper.getInsertAxhkPjClq(axhkPjClq);
                break;
            }
            case 8:{
                //接插件
                AxhkPjJcj axhkPjJcj = objectMapper.convertValue(obj,AxhkPjJcj.class);
                i = addObject.axhkPjJcjMapper.getInsertAxhkPjJcj(axhkPjJcj);
                break;
            }
            case 7:{
                //其它
                AxhkQtElse axhkQtElse = objectMapper.convertValue(obj,AxhkQtElse.class);
                i = addObject.axhkQtElseMapper.getInsertQtElse(axhkQtElse);
                break;
            }
        }
        return i;
    }
}
